#include <ptgui/ptgui.h>

void ptgui_gui_init(ptgui_gui_t *gui)
{
	ptgui_list_init(&gui->entities_list);
}

ptgui_gui_t * ptgui_gui_create(void)
{
	ptgui_gui_t *gui;

	gui = PTGUI_TYPE_MALLOC(ptgui_gui_t);
	if (gui == NULL) {
		return NULL;
	}

	ptgui_gui_init(gui);

	return gui;
}

void ptgui_gui_render(ptgui_gui_t *gui)
{
	struct ptgui_list_node *node;
	struct ptgui_widget *widget;

	ptgui_list_foreach(node, &(gui->entities_list))
	{
		widget = ptgui_list_entry(node, struct ptgui_widget, sibling);
		widget->render_handler(widget);
	}
}

void ptgui_gui_frame(ptgui_gui_t *gui, rt_uint32_t fDelta)
{
	struct ptgui_list_node *node;
	struct ptgui_widget *widget;

	ptgui_list_foreach(node, &(gui->entities_list))
	{
		widget = ptgui_list_entry(node, struct ptgui_widget, sibling);
		widget->frame_handler(widget, fDelta);
	}
}

void ptgui_gui_add(ptgui_gui_t *gui, ptgui_widget_t *widget)
{
	ptgui_list_append(&gui->entities_list, &widget->sibling);
}

void ptgui_gui_remove(ptgui_gui_t *gui, ptgui_widget_t *widget)
{
	ptgui_list_remove(&gui->entities_list, &widget->sibling);
}